package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class NoteAdapter extends StkProviderMultiAdapter<StkResBean> {

    public NoteAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new NoteProvider());
    }

    private boolean isShow = false;

    public void setShow(boolean show) {
        isShow = show;
    }

    private class NoteProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_note;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            Glide.with(baseViewHolder.itemView).load(bean.getThumbUrl()).into((ImageView) baseViewHolder.getView(R.id.ivNoteItemImg));
            baseViewHolder.setText(R.id.tvNoteItemName, bean.getName());
            baseViewHolder.setText(R.id.tvNoteItemDesc, bean.getDesc());
            Random random = new Random();
            int num = random.nextInt(1000) + 1000;
            baseViewHolder.setText(R.id.tvNoteItemGoodNum, getContext().getString(R.string.good_num, num));
            if (bean.isSelected()) {
                baseViewHolder.setImageResource(R.id.ivNoteItemGood, R.drawable.adianzan);
            } else {
                baseViewHolder.setImageResource(R.id.ivNoteItemGood, R.drawable.aweidianz);
            }
            if (isShow) {
                if (baseViewHolder.getBindingAdapterPosition() == 0) {
                    baseViewHolder.setImageResource(R.id.ivNoteItemLog, R.drawable.atop1);
                } else if (baseViewHolder.getBindingAdapterPosition() == 1) {
                    baseViewHolder.setImageResource(R.id.ivNoteItemLog, R.drawable.atop2);
                } else if (baseViewHolder.getBindingAdapterPosition() == 2) {
                    baseViewHolder.setImageResource(R.id.ivNoteItemLog, R.drawable.atop3);
                }else {
                    baseViewHolder.getView(R.id.ivNoteItemLog).setVisibility(View.GONE);
                }
            } else {
                baseViewHolder.getView(R.id.ivNoteItemLog).setVisibility(View.GONE);
            }
        }
    }

}
